
// import { Component, OnInit, Input } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { Hero } from '../hero'
import { ActivatedRoute as Route } from '@angular/router'
import { Location } from '@angular/common'
import { HeroService } from '../hero.service'

@Component({
  selector: 'app-hero-detail',
  templateUrl: './hero-detail.component.html',
  styleUrls: ['./hero-detail.component.less']
})



export class HeroDetailComponent implements OnInit {
  // @Input() hero:Hero
  hero: Hero
  id: number
  constructor(
    private route: Route,
    private heroService: HeroService,
    private location: Location
  ) { }

  ngOnInit(): void {
    this.init()
  }
  init() {
    this.getHero()
  }
  getHero() {
    this.id = +this.route.snapshot.paramMap.get('id')
    this.heroService.getHeroOne(this.id).subscribe(hero => this.hero = hero)
  }
  goBack() {
    this.location.back()
  }
}

